<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.util.*"%>
<%@ page import="com.ubadong.studentmng.vo.Student"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>学生管理</title>

<script type="text/javascript">
	function add(){
		location.href="student/student_add.jsp";
	}
	
	function edit(id){
		location.href="studentMNGServlet?method=edit&id="+id;
	}
	function removeAll(){
		var checkbox = document.getElementsByName("check");
		var ids = "";
		
		var count = 0;
		for (var i = 0; i < checkbox.length; i++) {
			if(checkbox[i].checked){
				count = count + 1;
				ids = ids + checkbox[i].value+",";
			}
		}
		
		if(count == 0){
			alert("请选择需要删除的数据！");
			return ;
		}
		
		ids = ids.substring(0, ids.lastIndexOf(","));
		remove(ids);
	}
	
	function remove(ids){
		location.href="studentMNGServlet?method=delete&ids="+ids;
	}
	function checkAll(checked){
		var checkbox = document.getElementsByName("check");
		for (var i = 0; i < checkbox.length; i++) {
			checkbox[i].checked=checked;
		}
	}
</script>
</head>
<body>

	<form action="studentMNGServlet?method=list" method="post">

		<table>
			<tr>
				<!-- 获取表单参数，如果是变量值就不需要param ，可以直接${变量名}-->
				<td>姓名：<input type="text" name="name" value="${param.name}"></td>
				<td>学历： 
				
				<select name="edu">
					<option value=""></option>
						<option value="专科" <c:if test="${param.edu =='专科' }" >selected='selected'</c:if>>专科</option>
						<option value="本科"<c:if test="${param.edu =='本科' }" >selected='selected'</c:if>>本科</option>
						<option value="硕士" <c:if test="${param.edu =='硕士' }" >selected='selected'</c:if>>硕士</option>
				</select>

				</td>
				<td>性别：
				<select name="gender">
					<option value="-1"></option>
					<option value="1" <c:if test="${param.gender ==1 }" >selected='selected'</c:if>>男</option>
					<option value="0" <c:if test="${param.gender ==2 }" >selected='selected'</c:if>>女</option>
				</select>
				</td>
				<td></td>
				<td><input type="submit" value="查询"></td>
			</tr>
		</table>

		<input type="button" value="增加" onclick="add();"><input type="button" value="删除" onclick="removeAll();">

		<table border=1 width=100% style="text-align:center">
			<tr>
				<th><input type="checkbox" name="checkall" onclick="checkAll(this.checked)"></th>
				<th>姓名</th>
				<th>年龄</th>
				<th>性别</th>
				<th>爱好</th>
				<th>生日</th>
				<th>学历</th>
				<th width="20%">操作</th>
			</tr>
			
			
			<c:forEach var="s" items="${result }">
			<tr>
				<td><input type="checkbox" name="check" value="${s.id}"></td>
				<td>${s.name}</td>
				<td>${s.age}</td>
				<td>
					<c:choose>
						<c:when test="${s.gender ==1}">
							男
						</c:when>
						<c:when test="${s.gender ==0}">
							女
						</c:when>					
					</c:choose>
				</td>
				<td>${s.hobby}</td>
				<td>${s.birthday}</td>
				<td>${s.edu}</td>
				<td><a href="javascript:edit(${s.id})">修改</a>&nbsp;&nbsp;&nbsp;<a
					href="javascript:remove(${s.id})">删除</a></td>
			</tr>
			</c:forEach>

		</table>
		
		<div>
			<a href="studentMNGServlet?method=list&currentPage=1">首页</a>
			<c:choose>
				<c:when test="${page.currentPage==1}">
					<a href="#">上一页</a>
				</c:when>
				<c:otherwise>
					<a href="studentMNGServlet?method=list&currentPage=${page.currentPage-1}">上一页</a>
				</c:otherwise>
			</c:choose>
			<c:choose>
				<c:when test="${page.currentPage==page.totalPage}">
					<a href="#">下一页</a>
				</c:when>
				<c:otherwise>
					<a href="studentMNGServlet?method=list&currentPage=${page.currentPage+1}">下一页</a>
				</c:otherwise>
			</c:choose>
			<a href="studentMNGServlet?method=list&currentPage=${page.totalPage}">尾页</a>
		</div>
		
		
		
		
		
		
	</form>
</body>
</html>